import Vue from 'vue'
import App from './App.vue'
import '@/utils/vant-ui'
import store from '@/store/index'
import router from '@/router'
import ArticleItem from '@/components/ArticleItem.vue'
import CommentItem from '@/components/CommentItem.vue'
import UserChannels from '@/components/UserChannels.vue'
import CommentEdit from '@/components/CommentEdit.vue'

// 引入 highlight.js 代码高亮工具
import hljs from 'highlight.js'
// 使用样式，有多种样式可选
import 'highlight.js/styles/darcula.css'
// 自定义指令v-highlight
Vue.directive('highlight', e => {
    // 找到e这个元素的所有指定子节点
    let codeBlocks = e.querySelectorAll('.cnblogs_Highlighter pre, .cnblogs_code pre, pre code')
    codeBlocks.forEach(item => {
        // 使给highlightBlock方法对每个节点进行处理，添加语法高亮
        hljs.highlightBlock(item)
        // hljs.highlightElement(item)
    })
})
// 增加组定义属性，用于在代码中预处理代码格式
Vue.prototype.$hljs = hljs

Vue.config.productionTip = false
Vue.component('ArticleItem', ArticleItem)
Vue.component('CommentItem', CommentItem)
Vue.component('UserChannels', UserChannels)
Vue.component('CommentEdit', CommentEdit)

new Vue({
    store,
    router,
    render: h => h(App)
}).$mount('#app')
